package com.fxhy.filter;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ControllorInterceptor implements HandlerInterceptor{

	@Override
	public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
	    log.info("---------------------开始进入请求地址拦截----------------------------");
//	    String token = httpServletRequest.getHeader("token");
//       
//        if(!"aOXnjYZyn==".equals(token)){
//            PrintWriter writer = null;
//            httpServletResponse.setCharacterEncoding("UTF-8");
//            httpServletResponse.setContentType("text/html; charset=utf-8");
//            try {
//                writer = httpServletResponse.getWriter();
//                String error = "token信息有误";
//                writer.print(error);
//                return false;
// 
//            } catch (IOException e) {
//                log.error("response error",e);
//            } finally {
//                if (writer != null)
//                    writer.close();
//            }
//        }
        return true;
	}
	
	@Override
	public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
	    log.info("--------------处理请求完成后视图渲染之前的处理操作---------------");
	}
	
	@Override
	public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
	    log.info("---------------视图渲染之后的操作-------------------------0");
	}
}
